package com.yc.game.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yc.game.pojo.Food;
import com.yc.game.service.FoodService;
import com.yc.game.dao.FoodMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FoodServiceImpl implements FoodService {
    @Autowired
    private FoodMapper foodMapper;

    /**
     * 查询所有的商品
     * @param pageSize
     * @param pageNum
     * @return
     */
    @Override
    public PageInfo<Food> getAll(Integer pageSize, Integer pageNum, Integer categoryId) {
        PageHelper.startPage(pageNum, pageSize);
        List<Food> foods = foodMapper.getAll(categoryId);
        PageInfo<Food> pageInfo = new PageInfo<>(foods);
        return pageInfo;
    }

    /**
     * 根据id查询商品详情
     * @param foodId
     * @return
     */
    @Override
    public Food getById(Integer foodId) {
        return foodMapper.selectByPrimaryKey(foodId);
    }

    /**
     * 查询热门商品
     * @return
     */
    @Override
    public List<Food> getByHot() {
        return foodMapper.getByHot();
    }

    @Override
    public PageInfo<Food> findFood(Integer pageSize, Integer pageNum, String foodName) {
        PageHelper.startPage(pageNum, pageSize);
        List<Food> foods = foodMapper.findFood(foodName);
        PageInfo<Food> pageInfo = new PageInfo<>(foods);
        return pageInfo;
    }

    /**
     * 获取最新三条
     * @return
     */
    @Override
    public List<Food> getByUpdateTime() {
        return foodMapper.getByUpdateTime();
    }

}
